package com.shanghe.house.controller;

import java.util.List;

import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.shanghe.house.common.Result;
import com.shanghe.house.dto.SceneDTO;
import com.shanghe.house.entity.Scene;
import com.shanghe.house.service.SceneService;

import jakarta.validation.Valid;

/**
 * 场景控制器
 */
@RestController
@RequestMapping("/api/scenes")
public class SceneController {
    private final SceneService sceneService;

    public SceneController(SceneService sceneService) {
        this.sceneService = sceneService;
    }

    @GetMapping
    public Result<List<Scene>> findAll() {
        return Result.success(sceneService.findAll());
    }

    @GetMapping("/{id}")
    public Result<Scene> findById(@PathVariable Long id) {
        return Result.success(sceneService.findById(id));
    }

    @PostMapping
    public Result<Scene> create(@Valid @RequestBody SceneDTO sceneDTO) {
        return Result.success(sceneService.create(sceneDTO));
    }

    @PutMapping("/{id}")
    public Result<Scene> update(@PathVariable Long id, @Valid @RequestBody SceneDTO sceneDTO) {
        return Result.success(sceneService.update(id, sceneDTO));
    }

    @DeleteMapping("/{id}")
    public Result<Void> delete(@PathVariable Long id) {
        sceneService.delete(id);
        return Result.success(null);
    }

    @PostMapping("/{id}/activate")
    public Result<Void> activate(@PathVariable Long id) {
        sceneService.activate(id);
        return Result.success(null);
    }
} 